﻿/* 2012/1/1 */
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Cosmos.Windows.Themes;

namespace PictureShower
{
    class ImageFolderListViewItem : ListViewItem
    {
        protected FolderInformation _folderInformation;

        public ImageFolderListViewItem()
        {
            _folderInformation = new FolderInformation();
            SubItems.AddRange(new string[] { String.Empty, String.Empty});
        }

        public ImageFolderListViewItem(string folderPath, bool containSubfolder,
            string includePattern, string excludePattern,
            GroupOption groupOption, string groupPattern, string groupNamePattern, bool enabled)
        {
            _folderInformation = new FolderInformation(folderPath, containSubfolder,
                includePattern, excludePattern, groupOption, groupPattern, groupNamePattern, enabled);
            SubItems.AddRange(new string[] { String.Empty, String.Empty });
            DisplayFolderPath();
            DisplayContainSubfolder();
            DisplayGroupOption();
            DisplayEnabled();
        }

        public ImageFolderListViewItem(string escapeString)
            : this()
        {
            _folderInformation.EscapeString = escapeString;
            DisplayFolderPath();
            DisplayContainSubfolder();
            DisplayGroupOption();
            DisplayEnabled();
        }

        public ImageFolderListViewItem(ImageFolderListViewItem item)
            : this()
        {
            _folderInformation.EscapeString = item.EscapeString;
            DisplayFolderPath();
            DisplayContainSubfolder();
            DisplayGroupOption();
            DisplayEnabled();
        }

        protected void DisplayFolderPath()
        {
            SubItems[0].Text = _folderInformation.FolderPath;
        }

        protected void DisplayContainSubfolder()
        {
            string text;
            if (_folderInformation.ContainSubfolder)
                text = "是";
            else
                text = "否";
            SubItems[1].Text = text;
        }

        protected void DisplayGroupOption()
        {
            SubItems[2].Text = GroupOptionHelper.GetDescription(_folderInformation.GroupOption);
        }

        protected void DisplayEnabled()
        {
            Checked = _folderInformation.Enabled;
        }

        public override object Clone()
        {
            ImageFolderListViewItem result = (ImageFolderListViewItem)(base.Clone());
            result._folderInformation = _folderInformation;
            return result;
        }

        public string FolderPath
        {
            get { return _folderInformation.FolderPath; }
            set 
            {
                _folderInformation.FolderPath = value;
                DisplayFolderPath();
            }
        }

        public bool ContainSubfolder
        {
            get { return _folderInformation.ContainSubfolder; }
            set 
            { 
                _folderInformation.ContainSubfolder = value;
                DisplayContainSubfolder();
            }
        }

        public string IncludePattern
        {
            get { return _folderInformation.IncludePattern; }
            set { _folderInformation.IncludePattern = value; }
        }

        public string ExcludePattern
        {
            get { return _folderInformation.ExcludePattern; }
            set { _folderInformation.ExcludePattern = value; }
        }

        public GroupOption GroupOption
        {
            get { return _folderInformation.GroupOption; }
            set
            { 
                _folderInformation.GroupOption = value;
                DisplayGroupOption();
            }
        }

        public string GroupPattern
        {
            get { return _folderInformation.GroupPattern; }
            set { _folderInformation.GroupPattern = value; }
        }

        public string GroupNamePattern
        {
            get { return _folderInformation.GroupNamePattern; }
            set { _folderInformation.GroupNamePattern = value; }
        }

        public bool Enabled
        {
            get { return _folderInformation.Enabled; }
            set 
            { 
                _folderInformation.Enabled = value;
                DisplayEnabled();
            }
        }

        public string EscapeString
        {
            get 
            {
                _folderInformation.Enabled = Checked;
                return _folderInformation.EscapeString; 
            }
            set
            {
                _folderInformation.EscapeString = value;
                DisplayFolderPath();
                DisplayContainSubfolder();
                DisplayGroupOption();
                DisplayEnabled();
            }
        }
    }
}
